package com.chouxiaozi.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @Value("${service-url.nacos-payment-service}")
    private String serverURL;

    @GetMapping(value = "/consumer/payment/nacos/{id}")
    @SentinelResource(fallback = "handleBlock")
    public String paymentInfo(@PathVariable("id") Long id)
    {
        int i= 1/0;
        return restTemplate.getForObject(serverURL+"/payment/nacos/"+id,String.class);
    }

    /**
     * 报错 降级处理方法
     * @param id
     * @return
     */
    public String handleBlock(@PathVariable("id") Long id)
    {
        return "服务维护中"+id;
    }
}
